(*
 * Primitive implementation of directed graphs.
 *
 * author: inky-kinky
 * contact: comamm@yandex.ru
 *
 * This code is distributed under the terms of GPL v.3 license.
 *)

type 'a node = { n : int; data : 'a }
type 'a graph

exception No_such_node

(* Graph construction. *)
val create : int -> 'a graph
val add_arc : 'a graph -> int -> int -> unit
val add_node : 'a graph -> 'a -> int
val add_unique_node : 'a graph -> 'a -> int

(* Graph statistics. *)
val n_nodes : 'a graph -> int
val n_arcs : 'a graph -> int

(* Graph searching. *)
val exists_node : ('a node -> bool) -> 'a graph -> bool
val find_node : ('a node -> bool) -> 'a graph -> 'a node
val neighbors : 'a graph -> 'a node -> 'a node list

(* Graph random walk. *)
val random_node : 'a graph -> 'a node
val random_neighbor : 'a graph -> 'a node -> 'a node
